// stores/userStore.js
import { defineStore } from 'pinia';

export const useUserStore = defineStore({
  id: 'user',
  state: () => ({
    userInfo: null,
    token: null,
  }),
  actions: {
    setUserInfo(info) {
      this.userInfo = info;
      localStorage.setItem('userInfo', JSON.stringify(info));
    },
    setToken(token) {
      this.token = token;
      localStorage.setItem('token', token);
    },
    clearUser() {
      this.userInfo = null;
      this.token = null;
      localStorage.removeItem('userInfo');
      localStorage.removeItem('token');
    },
  },
  getters: {
    isLoggedIn: (state) => !!state.token,
    getUserInfo: (state) => state.userInfo,
    getToken: (state) => state.token,
  },
});